function curry (fn, args = []) {
  return function () {
    let rest = [...args,...arguments]
    // 判断 rest 长度
    if (rest.length < fn.length)
      return curry.call(this, fn, rest)
    else
      return fn.apply(this, rest)
  }
}

function sum (a, b, c) {
  return a + b + c
}

let sumFn = curry(sum)
console.log(sumFn(1)(2)(3))
console.log(sumFn(1)(2, 3))
